package com.cci.kangdao.dto;

import com.cci.kangdao.entity.BaseEntity;
import com.gexin.fastjson.JSON;
import org.apache.log4j.Logger;

/**
 * @author William Du
 * @date 2019/12/30
 */
public class BaseResponse extends BaseEntity {
	private static Logger log = Logger.getLogger(BaseResponse.class.getName());
	private Integer status;

	private String msg;

	private Object data;

	public static BaseResponse success() {
		return success("执行成功！");
	}

	public static BaseResponse success(Object t) {
		BaseResponse result = new BaseResponse();
		result.setStatus(0);
		result.setMsg("执行成功！");
		result.setData(t);
		log.info("成功响应参数：" + JSON.toJSONString(result));
		return result;
	}

	public static BaseResponse success(String msg) {
		BaseResponse result = new BaseResponse();
		result.setStatus(0);
		result.setMsg(msg);
		log.info("成功响应参数：" + JSON.toJSONString(result));
		return result;
	}

	public static BaseResponse error(String msg) {
		return error(-99, msg);
	}

	public static BaseResponse error(Integer status, String msg) {
		BaseResponse result = new BaseResponse();
		result.setStatus(status);
		result.setMsg(msg);
		log.info("失败响应参数：" + JSON.toJSONString(result));
		return result;
	}

	public boolean isSuccess() {
		return this.status != null && this.status.intValue() == 0;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}
